#include <iostream>
#include <cstring>
#include <map>
using namespace std;
map<int,int>count;
int a[10000];
int main()
{
    int n,c,number=0;
    cin>>n>>c;
    memset(a,0,sizeof(a));
    //memset(count,0,sizeof(a));
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]-c>=0)
            count[a[i]-c]++;
            count[a[i]+c]++;
    }

    for(int i=1;i<=n;i++)
    {
        number+=count[a[i]];
    }
    cout << number/2<< endl;
    return 0;
}
